import React from 'react';
import {Affix as AntdAffix} from 'antd';
import {scrollTop} from '../util/utils';

class Affix extends React.Component {
	
	constructor(...args) {
		super(...args);
	}
	
	render() {
		return (
			<AntdAffix 
			className={this.props.className} 
			type={this.props.type} 
			offsetBottom={this.props.offsetBottom} 
			offsetTop={this.props.offsetTop === 0 ? 0.1 : this.props.offsetTop} 
			target={this.props.target} 
			onChange={this.props.onChange}>
        		{this.props.children}
        	</AntdAffix>
		);
	}
	
	componentDidMount() {
		window.setTimeout(() => {window.scrollTo(0, scrollTop() - 1);}, 100); // 触发解决Affix问题
	}
	
}

export default Affix;